[#import "/framework/JGP.htm"  as JGP]
<!--
项目   jgp-cloud-parent
作者   LOUFEI [Gavin]
时间   2019-11-02
-->
[@JGP.head "编辑列表项"/]
[@JGP.body]
    <jgp-div _row="['40','*']" _runit="px">
        <div slot="1-1">
            <jgp-btn _form="form" _fn="saveCallback">保存</jgp-btn>
        </div>
        <jgp-panel slot="2-1">
            <jgp-form _id="form" _action="/sys/dd/param-api-ctl/save-list-item">
                <jgp-text _name="parent.label" _label="从属" _col="12" _readonly="true"></jgp-text>
                <jgp-text _name="label" _label="LABEL" _col="12" _required="true"></jgp-text>
                <jgp-text _name="value" _label="VALUE" _col="12" _required="true" _onchange="fixValue"></jgp-text>
                <jgp-text _name="sort" _label="排序" _col="12" _required="true" _value="0"></jgp-text>
                <jgp-text _name="ext1" _label="扩展属性1" _col="12"></jgp-text>
                <jgp-text _name="ext2" _label="扩展属性2" _col="12"></jgp-text>
                <jgp-text _name="ext3" _label="扩展属性3" _col="12"></jgp-text>
            </jgp-form>
        </jgp-panel>
    </jgp-div>
[/@JGP.body]

[@JGP.foot]
    <script>
        var id = ${id!'null'};
        var parentId = ${parentId!'null'};
        var parent;

        JGP.$onload(function () {
            initItem();
        })

        function initItem() {
            var form = JGP.form('form');
            if (id) {
                JGP.$post('/sys/dd/param-api-ctl/query-list-item-one', {id: id}, function (res) {
                    form.setData(res.data.item)
                })
            } else if (parentId !== null) {
                form.field('parentId', parentId);
                JGP.$post('/sys/dd/param-api-ctl/query-list-item-one', {id: parentId}, function (res) {
                    if(res.flag){
                        parent = res.data.item;
                    }
                    if(parent){
                        form.field('parent.label', parent.label);
                    }
                })
            }
        }

        function saveCallback(result) {
            if (result.back.flag) {
                JGP.$alert('保存成功')
                JGP.$close(true);
            }
        }

        function fixValue(args) {
            var form = JGP.form('form');
            var value = args.back;
            if(value){
                form.field('value', value.toUpperCase());
            }

        }
    </script>
[/@JGP.foot]